#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3+10, INF=0x3f3f3f3f;
struct Edge{
    int v, w;
};
vector<Edge> G[maxn];
int mid, n, m;

int dfs(int u, int fa){
    if(G[u].size()==1 && u!=fa) return 0;
    int cost = 0;
    for(auto &e:G[u])if(e.v!=fa){
        int s = dfs(e.v, u);
        int w = e.w<=mid? e.w : 0;
        if(!s && !w) return 0;
        if(s && w) cost += min(s, w);
        else if(s) cost += s;
        else cost += w;
    }
    return cost <= m? cost : 0;
}

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    cin >> n >> m;
    int maxw = 0;
    for (int i = 0; i < n - 1; ++i) {
        int a, b, w; cin >> a >> b >> w;
        G[a].push_back({b, w});
        G[b].push_back({a, w});
        maxw = max(maxw, w);
    }

    int l=1, r=maxw, ans = 0;
    while (l <= r){
        mid = (l+r)/2;
        if(dfs(1, 1)) r = mid-1, ans = mid;
        else l = mid+1;
    }
    if(ans)cout << ans;
    else cout << -1;
    return 0;
}